﻿using AutoMapper;
using Domain.Flow;
using MediatR;
using U.B.ErrorCode;
using U.B.Repistory;
using U.B.WriteApi.Command.RabbitBWss;

namespace U.B.WriteApi.CommandHander.RabbitBWDD
{
    public class AddFirmCommandHander : IRequestHandler<AddFirmCommand, ApiResult<object>>
    {
        public readonly IRepistory<Firm> _firmRepository;
        public readonly IMapper _mapper;

        public AddFirmCommandHander(IRepistory<Firm> firmRepository, IMapper mapper)
        {
            _firmRepository = firmRepository;
            _mapper = mapper;
        }
        public Task<ApiResult<object>> Handle(AddFirmCommand request, CancellationToken cancellationToken)
        {
            ApiResult<object> apiResult = new ApiResult<object>();
            var result=_mapper.Map<Firm>(request);
            _firmRepository.Add(result);
            apiResult.Data = result;
            apiResult.Message = Renum.添加成功.ToString();
            apiResult.code = Renum.添加成功;
           return Task.FromResult(apiResult);
        }
    }
}
